/**
 * 请求接口
 */
const requestAjax = function(params) {
	
	var apiSite = "https://mayi.dlanqi.com:8007";

	if(!params['data']) {
		params['data'] = {};
	}
	
	const operationId = uni.getStorageSync('operationId');
	if (operationId) {
		params['header'] = {
			"operationId": operationId,
		};
	}
	params['data']['random'] = Math.random();
	
	return new Promise((resolve, reject) => {
		uni.request({
			url: apiSite + params['url'],
			method: params['method'],
			header: params['header'] || {},
			data: params['data'] || {},
			success: function(res) {
				// console.log(res);
				if (res.data.code != '200') {
				  uni.showToast({
				  	title: res.data.message || "未知异常",
					duration: 1500,
				  	icon: "none"
				  });
				  reject(res)
				} else {
				  resolve(res.data)
				}
			},
			fail: function(res) {
				console.log("fail-----",res)
				reject(res)
			}
		});
	})
}

export default {
	requestAjax
}

